import { request } from '@/utils/request'
import type {
  KnowledgeParams,
  KnowledgeResponse,
  DoctorParams,
  DoctorResponse,
  LikeFlag,
  DepResponseDate,
  Image,
  PrePayResponse,
  ConsultOrderPreParams,
  PartialConsult,
  ToPayParams,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from '@/types/consult'
import type { Patient } from '@/types/user'
// 获取知识列表
export const getKnowledgeListAPI = (params: KnowledgeParams) => {
  return request<KnowledgeResponse>('/patient/home/knowledge', 'GET', params)
}

// 获取医生列表
export const getDoctorListAPI = (params: DoctorParams) => {
  return request<DoctorResponse>('/home/page/doc', 'GET', params)
}

// 关注或去下关注类型接口
export const likeOrdislikeAPI = (id: string, type: LikeFlag = 'doc') => {
  return request('/like', 'POST', {
    id,
    type
  })
}

// 获取科室接口
export const getAllDepsAPI = () => {
  return request<DepResponseDate>('/dep/all')
}

// 上传文件接口
export const uploadImgAPI = (file: File) => {
  // 上传文件要用form.data封装
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 预支付API  preview预
export const prePayAPI = (params: ConsultOrderPreParams) => {
  return request<PrePayResponse>('/patient/consult/order/pre', 'GET', params)
}

// 患者详情
export const getPatientInfoAPI = (patientId: string) => {
  return request<Patient>(`/patient/info/${patientId}`, 'GET')
}

// 生成订单接口、
export const createOrderAPI = (consult: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', consult)
}

// 支付订单接口
export const createPayUrlAPI = (params: ToPayParams) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)
}

// 获取订单详情接口
export const getOrderDetailAPI = (orderId: string) => {
  return request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', {
    orderId
  })
}

// 查看处方接口
export const getPrescriptionAPI = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`)
}

// 提交评价接口
export const commitEvaluateAPI = (params: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: number
}) => {
  return request<{ id: string }>('/patient/order/evaluate', 'POST', params)
}

// 获取问诊记录接口
export const getConsultOrderListAPI = (params: ConsultOrderListParams) => {
  return request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)
}

// 取消问诊订单接口
export const canelOrderAPI = (id: string) => {
  return request(`/patient/order/cancel/${id}`, 'PUT')
}

// 删除问诊订单接口
export const delOrderAPI = (id: string) => {
  return request(`/patient/order/${id}`, 'DELETE')
}
